﻿using System;
using IcicleFramework.Components.Actions;
using IcicleFramework.Components.Renderable;
using IcicleFramework.Entities;
using IcicleFramework.GameServices;
using IcicleFramework.GameServices.HelperServices;
using IcicleFramework.Renderables;
using Microsoft.Xna.Framework;

namespace ExampleGame.Components.Actions
{
    public class ColorChangeAction : TimedAction
    {
        protected IRenderComponent renderableComponent;

        protected IRandomGenerator randomGenerator;

        protected override void Execute()
        {
            if (randomGenerator == null)
                randomGenerator = GameServiceManager.GetService<IRandomGenerator>();

            if (renderableComponent == null)
                renderableComponent = Parent.Parent.GetComponent<IRenderComponent>();

            if (renderableComponent != null && randomGenerator != null)
            {
                int r = randomGenerator.GenerateRandomInt(0, 255),
                    g = randomGenerator.GenerateRandomInt(0, 255),
                    b = randomGenerator.GenerateRandomInt(0, 255);

                ((SingleColorRenderable)renderableComponent.GetRenderable(0)).ColorChannel = new Color(r, g, b);
            }
        }

        public override IAction DeepClone()
        {
            return new ColorChangeAction();
        }
    }
}
